home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01a.txt / 000069_icon-group-sender _Tue Jun 27 12:52:55 2000.msg < prev    next >
Internet Message Format  |  2002-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id MAA14195
  4.     for icon-group-addresses; Tue, 27 Jun 2000 12:52:47 -0700 (MST)
  5. Message-Id: <200006271952.MAA14195@baskerville.CS.Arizona.EDU>
  6. From: gep2@terabites.com
  7. Date: Tue, 27 Jun 2000 14:39:11 -0500
  8. Subject: Permutations/Combinations
  9. To: icon-group@optima.CS.Arizona.EDU
  10. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  11. Status: RO
  12. Content-Length: 1351
  13.  
  14. > We have a brain teaser floating around work whose object is to find all 6-letter English words which can be made from the letters A, E, R, B,M and L.  I'm sure you can do this with Icon's reversible assignment, but I don't understand the latter.  Can anyone help me?
  15.  
  16. First off, one has to presume that you have available a list of English words from which universe you will find matching words that meet the criteria.
  17.  
  18. You can then either generate all possible permutations (which seems to be the approach you're taking) and then look each such word up in the list of valid English words, or else you can work the other way and use your list of words and qualify each to see if it fits the criteria.
  19.  
  20. I'd think that the second approach is simpler, although perhaps the first is faster.
  21.  
  22. Presuming that you have a file with one English-language word (all in lower case) per line:
  23.  
  24. procedure main()
  25.    while line := trim(read()) do {
  26.        if *line = 6 then
  27.           if *(line ** 'aerbml') = 6 then 
  28.         write(line)
  29.    }
  30. end
  31.  
  32. Character sets really make short work of many such problems.  :-)
  33.  
  34. Gordon Peterson
  35. http://web2.airmail.net/gep2/
  36. Support the Anti-SPAM Amendment!  Join at http://www.cauce.org/
  37. 12/19/98: the day the Conservatives demonstrated their scorn for their
  38.    fraudulent sham of representative government.  Voters, remember it!
  39.  
  40.